package com.ag.zrt.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ag.bean.TbPropose;
import com.ag.bean.TbUser;
import com.ag.bean.TbUserRole;
import com.ag.lzm.dao.TbUserRoleDAO;
import com.ag.zrt.dao.TbProposeDAO;
import com.ag.zrt.service.ZRTIUserRoleService;

@Service("ZRTUserRoleService")
public class ZRTUserRoleService implements ZRTIUserRoleService {
	@Resource(name = "LZMTbUserRoleDAO")
	private TbUserRoleDAO userRoleDAO;
	@Resource(name = "ZRTTbProposeDAO")
	private TbProposeDAO proposeDAO;

	public void setProposeDAO(TbProposeDAO proposeDAO) {
		this.proposeDAO = proposeDAO;
	}

	public void setUserRoleDAO(TbUserRoleDAO userRoleDAO) {
		this.userRoleDAO = userRoleDAO;
	}

	@Override
	public void chang(String UId, String eventId) throws Exception {
		// TODO Auto-generated method stub

		if (userRoleDAO.findByProperty("tbEvent.EId", eventId).size() > 0) {
			System.out.println("***************更改UID*************************************");
			TbUserRole ur = (TbUserRole) userRoleDAO.findByProperty(
					"tbEvent.EId", eventId).get(0);

			TbUser newUser = new TbUser();
			newUser.setUId(UId);

			ur.setTbUser(newUser);

			userRoleDAO.attachDirty(ur);
			System.out.println("***************更改UIDdone*************************************");
			
		}
		
		if(proposeDAO.findProposeByEventId(eventId) != null){
			System.out.println("***************更改UID in propose*************************************");
			TbPropose propose = proposeDAO.findProposeByEventId(eventId);
			TbUser newUserForPropose = new TbUser();
			
			newUserForPropose.setUId(UId);
			
			propose.setTbUserByPViceCommander(newUserForPropose);
			
			proposeDAO.attachDirty(propose);
			System.out.println("***************更改UID in propose done*************************************");
		}

	}

}
